package com.company.cloud.acct.modules.sdk.bankfour;

import cn.hutool.core.lang.Console;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.company.cloud.acct.modules.sdk.bankfour.enums.ApiCallTypeEnum;
import com.company.cloud.acct.modules.sdk.bankfour.model.BankFourReq;
import com.company.cloud.acct.modules.sdk.bankfour.model.BankFourResp;
import com.company.cloud.common.constant.BaseReturnEnum;
import com.company.cloud.common.exception.BusinessException;

import java.util.HashMap;
import java.util.Map;

public class BankFourApi {



    public static String bankFour_Str(BankFourApiConfig config, ApiCallTypeEnum callType, BankFourReq req){
        Map<String, Object> querys = new HashMap<String, Object>();
        querys.put("bankcard", req.getBankcard());
        querys.put("idcard", req.getIdcard());
        querys.put("phone", req.getPhone());
        querys.put("realname", req.getRealname());

        try {
            String body= HttpRequest.get("https://bankfour.market.alicloudapi.com/bankfour")
                    .header("Authorization","APPCODE " + config.getAppCode())
                    .form(querys)
                    .timeout(20000)
                    .execute().body();
            System.out.println("++++++++"+body);
            return body;
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException(BaseReturnEnum.SYSTEM_ERROR,e.getMessage());
        }
    }


    public static BankFourResp bankFour_AppCode(BankFourApiConfig config,BankFourReq req){
        String body=bankFour_Str(config,ApiCallTypeEnum.Ali_bank_AppCode,req);
        return JSON.parseObject(body,BankFourResp.class);
    }

    public static void main(String[] args) {
        BankFourApiConfig config=new BankFourApiConfig();
        BankFourReq req=new BankFourReq("1111111","320","18516098892","李明");
        String body= BankFourApi.bankFour_Str(config,ApiCallTypeEnum.Ali_bank_AppCode,req);
        System.out.println(body);

//        BankFourResp data= BankFourApi.bankFour_AppCode(config,req);
//        System.out.println(JSON.toJSONString(data));
    }


}
